﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DissipativeInputProcessing;

namespace ComputationVisualizer
{
    /// <summary>
    /// Interaction logic for FrameItem.xaml
    /// </summary>
    public partial class FrameItem : UserControl
    {
        public FrameItem()
        {
            InitializeComponent();
        }

        private IFrame _frame;
        public IFrame Frame {
            get { return _frame; }
            set { 
                _frame = value;
                textBlock.Text = _frame.Description;
            }
        }
        protected override void OnGotFocus(RoutedEventArgs e)
        {
            SetContentImage();
            base.OnGotFocus(e);
        }
        public void SetContentImage()
        {
            imageBox.Source = BitmapConverter.ToBitmapSource(_frame.Image);
            textBlock.Visibility=Visibility.Collapsed;
            imageBox.Visibility = Visibility.Visible;
        }
        public void SetFrameImage()
        {
            textBlock.Visibility = Visibility.Visible;
            imageBox.Visibility = Visibility.Collapsed;
        }
        protected override void OnLostFocus(RoutedEventArgs e)
        {
            SetFrameImage();
            base.OnLostFocus(e);
        }

        public void UpdateImage()
        {
            imageBox.Source = BitmapConverter.ToBitmapSource(_frame.Image);
        }
    }
}
